/*objperson.java
*
* Created on Sun Apr 06 21:28:39 BRT 2008
*
* @author Renato ferreira dos santos
*/
package rad.Java.Common.Class;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Person extends DefaultClass implements IClass{
    // <editor-fold defaultstate="collapsed" desc="Declaration of variables">
        private String _type;
        private String _name;
        private String _cpf_cnpj;
        private String _rg_ie;
        private String _phone1;
        private String _phone2;
        private String _fax;
        private String _celular;
        private String _branch;
        private String _address;
        private String _complement;
        private String _zip_code;
        private String _city;
        private String _sector;
        private String _state;
        private String _born_date;
        private String _register_date;
        private String _nationality;
        private String _naturalness;
        private String _marital_status;
        private String _sex;
        private String _email;
        private String _status;
        private String _enabled;
        private String _code;
        private String _name_responsible;
        private String _document_responsible;
        private String _username;
        private String _password;
    // </editor-fold>

    public Person (){
        _gsql.setTable("person");
        _sequence = "person_person_id_seq";
    }

    // <editor-fold defaultstate="collapsed" desc="Declaration of methods Get and Set">
        public void setPersonType (String value){
             this._type = value;
        }

        public String getPersonType(){
             return this._type;
        }

        public void setPersonName (String value){
             this._name = value;
        }

        public String getPersonName(){
             return this._name;
        }

        public void setPersonCpfCnpj (String value){
             this._cpf_cnpj = value;
        }

        public String getPersonCpfCnpj(){
             return this._cpf_cnpj;
        }

        public void setPersonRgIe(String value){
             this._rg_ie = value;
        }

        public String getPersonRgIe(){
             return this._rg_ie;
        }

        public void setPersonPhone1 (String value){
             this._phone1 = value;
        }

        public String getPersonPhone1(){
             return this._phone1;
        }

        public void setPersonPhone2 (String value){
             this._phone2 = value;
        }

        public String getPersonPhone2(){
             return this._phone2;
        }

        public void setPersonFax (String value){
             this._fax = value;
        }

        public String getPersonFax(){
             return this._fax;
        }

        public void setPersonCellular (String value){
             this._celular = value;
        }

        public String getPersonCellular(){
             return this._celular;
        }

        public void setPersonBranch (String value){
             this._branch = value;
        }

        public String getPersonBranch(){
             return this._branch;
        }

        public void setPersonAddress (String value){
             this._address = value;
        }

        public String getPersonAddress(){
             return this._address;
        }

        public void setPersonComplement (String value){
             this._complement = value;
        }

        public String getPersonComplement(){
             return this._complement;
        }

        public void setPersonZipCode (String value){
             this._zip_code = value;
        }

        public String getPersonZipCode(){
             return this._zip_code;
        }

        public void setPersonCity (String value){
             this._city = value;
        }

        public String getPersonCity(){
             return this._city;
        }

        public void setPersonSector (String value){
             this._sector = value;
        }

        public String getPersonSector(){
             return this._sector;
        }

        public void setPersonState (String value){
             this._state = value;
        }

        public String getPersonState(){
             return this._state;
        }

        public void setPersonBornDate (String value){
             this._born_date = value;
        }

        public String getPersonBornDate(){
             return this._born_date;
        }

        public void setPersonRegisterDate (String value){
             this._register_date = value;
        }

        public String getPersonRegisterDate(){
             return this._register_date;
        }

        public void setPersonNationality (String value){
             this._nationality = value;
        }

        public String getPersonNationality(){
             return this._nationality;
        }

        public void setPersonNaturalness (String value){
             this._naturalness = value;
        }

        public String getPersonNaturalness(){
             return this._naturalness;
        }

        public void setPersonMaritalStatus (String value){
             this._marital_status = value;
        }

        public String getPersonMaritalStatus(){
             return this._marital_status;
        }

        public void setPersonSex (String value){
             this._sex = value;
        }

        public String getPersonSex(){
             return this._sex;
        }

        public void setPersonEmail (String value){
             this._email = value;
        }

        public String getPersonEmail(){
             return this._email;
        }

        public void setPersonStatus (String value){
             this._status = value;
        }

        public String getPersonStatus(){
             return this._status;
        }

        public void setPersonEnabled (String value){
             this._enabled = value;
        }

        public String getPersonEnabled(){
             return this._enabled;
        }

        public void setPersonCode (String value){
             this._code = value;
        }

        public String getPersonCode(){
             return this._code;
        }

        public void setPersonNameResponsible (String value){
             this._name_responsible = value;
        }

        public String getPersonNameResponsible(){
             return this._name_responsible;
        }

        public void setPersonDocumentResponsible (String value){
             this._document_responsible = value;
        }

        public String getPersonDocumentResponsible(){
             return this._document_responsible;
        }

        public void setPersonUsername (String value){
             this._username = value;
        }

        public String getPersonUsername(){
             return this._username;
        }

        public void setPersonPassword (String value){
             this._password = value;
        }

        public String getPersonPassword(){
             return this._password;
        }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Declaration of functions">
        public void clear(){
            _id                         = "";
            _type                       = "";
            _name                       = "";
            _cpf_cnpj                   = "";
            _rg_ie                      = "";
            _phone1                     = "";
            _phone2                     = "";
            _fax                        = "";
            _celular                    = "";
            _branch                     = "";
            _address                    = "";
            _complement                 = "";
            _zip_code                   = "";
            _city                       = "";
            _sector                     = "";
            _state                      = "";
            _born_date                  = "";
            _register_date              = "";
            _nationality                = "";
            _naturalness                = "";
            _marital_status             = "";
            _sex                        = "";
            _email                      = "";
            _status                     = "";
            _enabled                    = "";
            _code                       = "";
            _name_responsible           = "";
            _document_responsible       = "";
            _username                   = "";
            _password                   = "";
        }

        @Override
        public void get(ResultSet rs) {
            try {
                _id                         = rs.getString("person_id");
                _type                       = rs.getString("person_type");
                _name                       = rs.getString("person_name");
                _cpf_cnpj                   = rs.getString("person_cpf_cnpj");
                _rg_ie                      = rs.getString("person_rg_ie");
                _phone1                     = rs.getString("person_phone1");
                _phone2                     = rs.getString("person_phone2");
                _fax                        = rs.getString("person_fax");
                _celular                    = rs.getString("person_celular");
                _branch                     = rs.getString("person_branch");
                _address                    = rs.getString("person_address");
                _complement                 = rs.getString("person_complement");
                _zip_code                   = rs.getString("person_zip_code");
                _city                       = rs.getString("person_city");
                _sector                     = rs.getString("person_sector");
                _state                      = rs.getString("person_state");
                _born_date                  = rs.getString("person_born_date");
                _register_date              = rs.getString("person_register_date");
                _nationality                = rs.getString("person_nationality");
                _naturalness                = rs.getString("person_naturalness");
                _marital_status             = rs.getString("person_marital_status");
                _sex                        = rs.getString("person_sex");
                _email                      = rs.getString("person_email");
                _status                     = rs.getString("person_status");
                _enabled                    = rs.getString("person_enabled");
                _code                       = rs.getString("person_code");
                _name_responsible           = rs.getString("person_name_responsible");
                _document_responsible       = rs.getString("person_document_responsible");
                _username                   = rs.getString("person_username");
                _password                   = rs.getString("person_password");
            } catch (SQLException ex) {
                Logger.getLogger(Person.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        @Override
        public void setGsql() {
            _gsql.setValue( _id                         , "person_id");
            _gsql.setValue( _type                       , "person_type");
            _gsql.setValue( _name                       , "person_name");
            _gsql.setValue( _cpf_cnpj                   , "person_cpf_cnpj");
            _gsql.setValue( _rg_ie                      , "person_rg_ie");
            _gsql.setValue( _phone1                     , "person_phone1");
            _gsql.setValue( _phone2                     , "person_phone2");
            _gsql.setValue( _fax                        , "person_fax");
            _gsql.setValue( _celular                    , "person_celular");
            _gsql.setValue( _branch                     , "person_branch");
            _gsql.setValue( _address                    , "person_address");
            _gsql.setValue( _complement                 , "person_complement");
            _gsql.setValue( _zip_code                   , "person_zip_code");
            _gsql.setValue( _city                       , "person_city");
            _gsql.setValue( _sector                     , "person_sector");
            _gsql.setValue( _state                      , "person_state");
            _gsql.setValue( _born_date                  , "person_born_date");
            _gsql.setValue( _register_date              , "person_register_date");
            _gsql.setValue( _nationality                , "person_nationality");
            _gsql.setValue( _naturalness                , "person_naturalness");
            _gsql.setValue( _marital_status             , "person_marital_status");
            _gsql.setValue( _sex                        , "person_sex");
            _gsql.setValue( _email                      , "person_email");
            _gsql.setValue( _status                     , "person_status");
            _gsql.setValue( _enabled                    , "person_enabled");
            _gsql.setValue( _code                       , "person_code");
            _gsql.setValue( _name_responsible           , "person_name_responsible");
            _gsql.setValue( _document_responsible       , "person_document_responsible");
            _gsql.setValue( _username                   , "person_username");
            _gsql.setValue( _password                   , "person_password");
        }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="old methods">

    /* public boolean Get()
    {

         String sql;
         try
         {
                 sql = " SELECT person_id, person_type, person_name, person_cpf_cnpj, person_rg_ie, person_phone1, person_phone2, person_fax, person_cellular, person_branch, person_address, person_complement, person_zip_code, person_city, person_sector, person_state, person_born_date, person_register_date, person_nationality, person_naturalness, person_marital_status, person_sex, person_email, person_status, person_enabled, person_code, person_name_responsible, person_document_responsible, person_username, person_password, person_person_id FROM person  WHERE (person_id = " + person_id + ")";
                 resultset = database.executeQueryRs(sql);
                 resultset.next();
                 person_type= resultset.getString("person_type");
                 person_name= resultset.getString("person_name");
                 person_cpf_cnpj= resultset.getString("person_cpf_cnpj");
                 person_rg_ie= resultset.getString("person_rg_ie");
                 person_phone1= resultset.getString("person_phone1");
                 person_phone2= resultset.getString("person_phone2");
                 person_fax= resultset.getString("person_fax");
                 person_cellular= resultset.getString("person_cellular");
                 person_branch= resultset.getString("person_branch");
                 person_address= resultset.getString("person_address");
                 person_complement= resultset.getString("person_complement");
                 person_zip_code= resultset.getString("person_zip_code");
                 person_city= resultset.getString("person_city");
                 person_sector= resultset.getString("person_sector");
                 person_state= resultset.getString("person_state");
                 person_born_date= resultset.getString("person_born_date");
                 person_register_date= resultset.getString("person_register_date");
                 person_nationality= resultset.getString("person_nationality");
                 person_naturalness= resultset.getString("person_naturalness");
                 person_marital_status= resultset.getString("person_marital_status");
                 person_sex= resultset.getString("person_sex");
                 person_email= resultset.getString("person_email");
                 person_status= resultset.getString("person_status");
                 person_enabled= resultset.getBoolean("person_enabled");
                 person_code= resultset.getString("person_code");
                 person_name_responsible= resultset.getString("person_name_responsible");
                 person_document_responsible= resultset.getString("person_document_responsible");
                 person_username= resultset.getString("person_username");
                 person_password= resultset.getString("person_password");
                 person_person_id= resultset.getInt("person_person_id");
                 return true;
         }
         catch(Exception ex)
         {
                 JOptionPane.showMessageDialog(null, "Opera??o n?o pode ser executada!" + "\n" + ex);
                 return false;
         }
    }

    public boolean Save()
    {

         String sql;
         try
         {
                 sql =  " INSERT INTO person( person_id, person_type, person_name, person_cpf_cnpj, person_rg_ie, person_phone1, person_phone2, person_fax, person_cellular, person_branch, person_address, person_complement, person_zip_code, person_city, person_sector, person_state, person_born_date, person_register_date, person_nationality, person_naturalness, person_marital_status, person_sex, person_email, person_status, person_enabled, person_code, person_name_responsible, person_document_responsible, person_username, person_password, person_person_id) VALUES(" + person_id + " , '" + person_type + "', '" + person_name + "', '" + person_cpf_cnpj + "', '" + person_rg_ie + "', '" + person_phone1 + "', '" + person_phone2 + "', '" + person_fax + "', '" + person_cellular + "', '" + person_branch + "', '" + person_address + "', '" + person_complement + "', '" + person_zip_code + "', '" + person_city + "', '" + person_sector + "', '" + person_state + "', '" + person_born_date + "', '" + person_register_date + "', '" + person_nationality + "', '" + person_naturalness + "', '" + person_marital_status + "', '" + person_sex + "', '" + person_email + "', '" + person_status + "', '" + person_enabled + "', '" + person_code + "', '" + person_name_responsible + "', '" + person_document_responsible + "', '" + person_username + "', '" + person_password + "', " + person_person_id + " )" ;
                 database.executeCommand(sql, database.doNotUseTransaction);
                 if (database.Error)
                 {
                         JOptionPane.showMessageDialog(null, "Opera??o n?o pode ser executada!" + "\n" + database.ErrorMessage);
                         return false;
                 }
                 else
                 {
                         JOptionPane.showMessageDialog(null, "Opera??o efetuada com sucesso! " );
                         return true;
                 }
         }
         catch(Exception ex)
         {
                 JOptionPane.showMessageDialog(null, "Opera??o n?o pode ser executada!" + "\n" + ex);
                 return false;
         }
    }

    public boolean Update()
    {

         String sql;
         try
         {
                 sql = " UPDATE person SET (" + "person_id = " + "'" + person_id + "'" + " , " + "person_type = " + "'" + person_type + "'" + " , " + "person_name = " + "'" + person_name + "'" + " , " + "person_cpf_cnpj = " + "'" + person_cpf_cnpj + "'" + " , " + "person_rg_ie = " + "'" + person_rg_ie + "'" + " , " + "person_phone1 = " + "'" + person_phone1 + "'" + " , " + "person_phone2 = " + "'" + person_phone2 + "'" + " , " + "person_fax = " + "'" + person_fax + "'" + " , " + "person_cellular = " + "'" + person_cellular + "'" + " , " + "person_branch = " + "'" + person_branch + "'" + " , " + "person_address = " + "'" + person_address + "'" + " , " + "person_complement = " + "'" + person_complement + "'" + " , " + "person_zip_code = " + "'" + person_zip_code + "'" + " , " + "person_city = " + "'" + person_city + "'" + " , " + "person_sector = " + "'" + person_sector + "'" + " , " + "person_state = " + "'" + person_state + "'" + " , " + "person_born_date = " + "'" + person_born_date + "'" + " , " + "person_register_date = " + "'" + person_register_date + "'" + " , " + "person_nationality = " + "'" + person_nationality + "'" + " , " + "person_naturalness = " + "'" + person_naturalness + "'" + " , " + "person_marital_status = " + "'" + person_marital_status + "'" + " , " + "person_sex = " + "'" + person_sex + "'" + " , " + "person_email = " + "'" + person_email + "'" + " , " + "person_status = " + "'" + person_status + "'" + " , " + "person_enabled = " + "'" + person_enabled + "'" + " , " + "person_code = " + "'" + person_code + "'" + " , " + "person_name_responsible = " + "'" + person_name_responsible + "'" + " , " + "person_document_responsible = " + "'" + person_document_responsible + "'" + " , " + "person_username = " + "'" + person_username + "'" + " , " + "person_password = " + "'" + person_password + "'" + " , " + "person_person_id = " + "'" + person_person_id + "'" + " )" + " WHERE (" + "person_id = " + person_id + ")";
                 database.executeCommand(sql, database.doNotUseTransaction);
                 if (database.Error)
                 {
                         JOptionPane.showMessageDialog(null, "Opera??o n?o pode ser executada!" + "\n" + database.ErrorMessage);
                         return false;
                 }
                 else
                 {
                         JOptionPane.showMessageDialog(null, "Opera??o efetuada com sucesso! " );
                         return true;
                 }
         }
         catch(Exception ex)
         {
                 JOptionPane.showMessageDialog(null, "Opera??o n?o pode ser executada!" + "\n" + ex);
                 return false;
         }
    }

    public boolean Delete()
    {

         String sql;
         try
         {
                 sql = " DELETE FROM person" + " WHERE (" + "person_id = " + person_id + ") AND (" + "person_type = " + "'" + person_type + "') AND (" + "person_name = " + "'" + person_name + "') AND (" + "person_cpf_cnpj = " + "'" + person_cpf_cnpj + "') AND (" + "person_rg_ie = " + "'" + person_rg_ie + "') AND (" + "person_phone1 = " + "'" + person_phone1 + "') AND (" + "person_phone2 = " + "'" + person_phone2 + "') AND (" + "person_fax = " + "'" + person_fax + "') AND (" + "person_cellular = " + "'" + person_cellular + "') AND (" + "person_branch = " + "'" + person_branch + "') AND (" + "person_address = " + "'" + person_address + "') AND (" + "person_complement = " + "'" + person_complement + "') AND (" + "person_zip_code = " + "'" + person_zip_code + "') AND (" + "person_city = " + "'" + person_city + "') AND (" + "person_sector = " + "'" + person_sector + "') AND (" + "person_state = " + "'" + person_state + "') AND (" + "person_born_date = " + "'" + person_born_date + "') AND (" + "person_register_date = " + "'" + person_register_date + "') AND (" + "person_nationality = " + "'" + person_nationality + "') AND (" + "person_naturalness = " + "'" + person_naturalness + "') AND (" + "person_marital_status = " + "'" + person_marital_status + "') AND (" + "person_sex = " + "'" + person_sex + "') AND (" + "person_email = " + "'" + person_email + "') AND (" + "person_status = " + "'" + person_status + "') AND (" + "person_enabled = " + "'" + person_enabled + "') AND (" + "person_code = " + "'" + person_code + "') AND (" + "person_name_responsible = " + "'" + person_name_responsible + "') AND (" + "person_document_responsible = " + "'" + person_document_responsible + "') AND (" + "person_username = " + "'" + person_username + "') AND (" + "person_password = " + "'" + person_password + "') AND (" + "person_person_id = " + person_person_id + ")";
                 database.executeCommand(sql, database.doNotUseTransaction);
                 if (database.Error)
                 {
                         JOptionPane.showMessageDialog(null, "Opera??o n?o pode ser executada!" + "\n" + database.ErrorMessage);
                         return false;
                 }
                 else
                 {
                         JOptionPane.showMessageDialog(null, "Opera??o efetuada com sucesso! " );
                         return true;
                 }
         }
         catch(Exception ex)
         {
                 JOptionPane.showMessageDialog(null, "Opera??o n?o pode ser executada!" + "\n" + ex);
                 return false;
         }
    }

    public DataSet Search()
    {

         DataSet ds;
         String sql;
         try
         {
                 sql = " SELECT person_id, person_type, person_name, person_cpf_cnpj, person_rg_ie, person_phone1, person_phone2, person_fax, person_cellular, person_branch, person_address, person_complement, person_zip_code, person_city, person_sector, person_state, person_born_date, person_register_date, person_nationality, person_naturalness, person_marital_status, person_sex, person_email, person_status, person_enabled, person_code, person_name_responsible, person_document_responsible, person_username, person_password, person_person_id FROM person ";
                 ds = database.executeQuery(sql);
                 if (database.Error)
                 {
                         return null;
                 }
                 else
                 {
                         return ds;
                 }
         }
         catch(Exception ex)
         {
                 return null;
         }
    }*/
    // </editor-fold>

} 